package main

import (
	"encoding/json"
	"fmt"
)

type Result2 struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func main() {
	var res Result2
	res.Code = 200
	res.Message = "success"

	toJson(&res)

	setData(&res)

	toJson(&res)

	fmt.Printf("res: %+v\n", res) // 500 fail
}

func setData(res *Result2) {
	res.Code = 500
	res.Message = "fail"
}

func toJson(res *Result2) {
	json, errs := json.Marshal(res)
	if errs != nil {
		fmt.Println("json marshal error:", errs)
	}
	fmt.Println("json data:", string(json))
}
